package net.phoenix.repository.value;

import javax.jcr.Node;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;

import net.phoenix.repository.RepositoryRuntimeException;

/**
 * 
 * Jigsaw server
 * 
 * @author <a href="shamphone@gmail.com">Li XiongFeng</a>
 * @date 2012-1-3
 * @version 1.0.0
 */
public class ReferenceValue extends BasicValue {
	private String value;

	public ReferenceValue(Node value) {
		try {
			this.value = value.getIdentifier();
		} catch (RepositoryException e) {
			throw new RepositoryRuntimeException(e);
		}
	}

	public ReferenceValue(String value) {
		this.value = value;
	}

	public String getString() throws RepositoryException {
		return this.value;
	}

	public int getType() {
		return PropertyType.REFERENCE;
	}

	public int compareTo(Value o) {
		return ((ReferenceValue) o).value.compareTo(this.value);
	}

	public boolean equals(Object o) {
		return ((ReferenceValue) o).value.equals(this.value);

	}

}
